<template>
	<div class="modal fade" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title">{{operationName}}分类</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal">	
						
						<div class="form-group">
							<label class="col-sm-2 control-label">父类名称</label>
							<div class="col-sm-10">
								<p class="form-control-static" >{{parentName}}</p>
							</div>
						</div>			
						
						<div class="form-group">
							<label class="col-sm-2 control-label">分类名称</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="category.name">
							</div>
						</div>			
																	
						
						<div class="form-group">
							<label class="col-sm-2 control-label">顺序</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="category.sort">
							</div>
						</div>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" @click="save">{{operationName}}</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
</template>

<script>
export default{
	data() {
		return {
			
		}
	},
	props: {
		category: Object
	},
	computed: {
		operationName() {
			return this.category.id ? "修改" : "新增"
		},
		parentName() {
			return this.$parent.isAdd1 ? '无' : this.$parent.activeCategory.name
		}
	},
	methods: {
		save() {
			let url = process.env.VUE_APP_SERVER + 'business/admin/category/save'
			this.$axios.post(url, this.category)
				.then(res => {
					if(res.data.status === 1) {
						this.$toast(this.operationName + '分类成功', this.$global.toast.success)
						$('#save-modal').modal('hide')
						this.$parent.all()
					}else {
						this.$toast(res.data.msg, this.$global.toast.fail)
					}
				})
		}
	}
}	
</script>

<style>
</style>
